package com.example.xm.customizing;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.danikula.videocache.HttpProxyCacheServer;
import com.example.xm.app.MyApp;

import cn.jzvd.JzvdStd;

public class PlayVideo extends JzvdStd {

    private Context context;

    public PlayVideo(Context context) {
        super(context);
        this.context = context;
    }

    public PlayVideo(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public void setUp(String url, String title, int screen, Class mediaInterfaceClass) {
        super.setUp(url, title, screen, mediaInterfaceClass);
        titleTextView.setTextColor(Color.RED);
        titleTextView.setPadding(100, titleTextView.getPaddingTop(), titleTextView.getPaddingRight(), titleTextView.getPaddingBottom());
        setScreen(screen);
    }

    @Override
    public void setUp(String url, String title) {
        super.setUp(url, title);
        //修改标题的文字颜色
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) titleTextView.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = (RelativeLayout.LayoutParams) new ViewGroup.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        layoutParams.leftMargin = 80;

        titleTextView.setTextColor(Color.RED);
        if (url.startsWith("http")) {//如果是网络资源缓存
            HttpProxyCacheServer proxy = MyApp.getProxy(context);
            String proxyUrl = proxy.getProxyUrl(url);
            super.setUp(proxyUrl, title);
        } else {
            super.setUp(url, title);
        }
    }
}
